#region Imports

using System;
using IEC.ColumnOrdering.SP2007.Application.Domain;
using Microsoft.SharePoint;

#endregion

namespace IEC.ColumnOrdering.SP2007.Application.Services.Concrete
{

    /// <summary>
    /// Provides functionality to convert webs.
    /// </summary>
    internal static class WebConverter
    {

        #region Constants

        #endregion

        #region Methods - Static Member

        /// <summary>
        /// Converts the given SharePoint web collection to a collection of webs.
        /// </summary>
        /// <param name="sharepointWebCollection">
        /// The SharePoint web collection to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointWebCollection"/>.
        /// </returns>
        public static WebCollection Convert(SPWebCollection sharepointWebCollection)
        {
            WebCollection webCollection = new WebCollection();

            foreach (SPWeb sharepointWeb in sharepointWebCollection)
            {
                Web web = WebConverter.Convert(sharepointWeb);

                webCollection.Add(web);
            }

            return webCollection;
        }

        /// <summary>
        /// Converts the given SharePoint web to a web.
        /// </summary>
        /// <param name="sharepointWeb">
        /// The SharePoint web to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointWeb"/>.
        /// </returns>
        public static Web Convert(SPWeb sharepointWeb)
        {
            Web web = new Web();
            
            // set properties
            web.Id = sharepointWeb.ID;
            web.Name = sharepointWeb.Name;
            web.DisplayName = sharepointWeb.Title;
            web.Url = new Uri(sharepointWeb.Url);

            return web;
        }

        #endregion

    }

}
